//
//  SecondTableViewCell.m
//  NewMusic
//
//  Created by chuxinyu123 on 15/11/23.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "SecondTableViewCell.h"

@interface SecondTableViewCell ()

@end
@implementation SecondTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self buildTableView];
    }
    return self;
}
- (void)buildTableView
{
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.songerNameLabel = [[UILabel alloc] init];
    self.songerNameLabel.textColor = [UIColor whiteColor];
    self.picImageView = [[UIImageView alloc] init];
    self.buttonImageView = [[UIImageView alloc] init];
    
    [self.contentView addSubview:_titleLabel];
    [self.contentView addSubview:_songerNameLabel];
    [self.contentView addSubview:_picImageView];
    [self.contentView addSubview:_buttonImageView];
    
    [_titleLabel release];
    [_songerNameLabel release];
    [_picImageView release];
    [_buttonImageView release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.picImageView.frame = CGRectMake(10, 10, self.frame.size.height - 20, self.frame.size.height - 20);
    self.titleLabel.frame = CGRectMake(_picImageView.frame.size.width + _picImageView.frame.origin.x + 10, 15, self.frame.size.width - _titleLabel.frame.origin.x, 30);
    self.songerNameLabel.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.frame.size.height + _titleLabel.frame.origin.y, _titleLabel.frame.size.width, 30);
    self.buttonImageView.frame = CGRectMake(self.frame.size.width - 60, (self.frame.size.height - 30) / 2, 30, 30);
}

- (void)setSecondModel:(SecondModel *)secondModel
{
    if (_secondModel != secondModel) {
        [_secondModel release];
        _secondModel = [secondModel retain];
    }
    self.titleLabel.text = secondModel.name;
    self.songerNameLabel.text = [NSString stringWithFormat:@"%@ %@", secondModel.singerName, secondModel.publishDate];
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:secondModel.picUrl]];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
